﻿using System;
using System.Collections;
using System.Windows;
using VirtualizingTreeView.Control;

namespace VirtualizingTreeView.Demo
{
	public partial class MainPage 
	{
		public MainPage()
		{
			InitializeComponent();
		}

		private void OnTree1Expanded( Object sender, VirtualizingEventArgs e )
		{
			Tree1.Add( e.Item, GenerateData() );
		}

		private void OnTree2Expanded( Object sender, VirtualizingEventArgs e )
		{
			Tree2.Add( e.Item, GenerateData() );
		}

		private void OnTree1SelectionChanged( Object sender, VirtualizingSelectionEventArgs e )
		{
			if( e.Added != null )
			{
				MessageBox.Show( "Selected: " + e.Added );
			}

			if( e.Removed != null )
			{
				MessageBox.Show( "Unselected: " + e.Removed );
			}
		}

		private void OnTree2SelectionChanged( Object sender, VirtualizingSelectionEventArgs e )
		{
			if(e.Added != null)
			{
				MessageBox.Show( "Selected: " + e.Added );	
			}

			if(e.Removed != null)
			{
				MessageBox.Show( "Unselected: " + e.Removed );
			}
		}

		private void OnUserControlLoaded( Object sender, RoutedEventArgs e )
		{
			Tree1.Add( GenerateData() );
			Tree2.Add( GenerateData() );
		}

		private static IEnumerable GenerateData()
		{
			for(Int32 i = 0; i < 10000; ++i)
			{
				yield return new DataObject
				             {
				             	Data = i.ToString()
				             };
			}
		}

	}
}
